<template>
	<div class="outerFrame">
		<div class="operator" style="font-size: 28px;">
			<el-card>
				<center>{{new Date() |dateformat}} {{state==1?'午餐段':'晚餐段'}}</center>
			</el-card>
		</div>
		<div class="dataTable" v-if="listData">
			<el-table :data="listData.records" stripe border height="85%" v-loading="listLoading" @selection-change="selectionChange">
				<el-table-column label="序号" width="55" fixed="left" align="center"><template scope="scope">
						<span>{{scope.$index+1}}</span>
					</template>
				</el-table-column>
				<el-table-column prop="eaddrs" label="公司地址"></el-table-column>
				<el-table-column prop="exptxt" label="套餐供应">
					<template slot-scope="scope" v-if="scope.row.exptxt">
						<div v-for="item,index in scope.row.exptxt">
							<span>{{index+1}}.{{item.name}}</span>
						</div>
					</template>
				</el-table-column>
				<el-table-column prop="jdtm" label="接单时间"><template slot-scope="scope">{{scope.row.jdtm}}</template></el-table-column>
				<el-table-column prop="neworder" label="新订单"></el-table-column>
				<el-table-column prop="jieorder" label="已接单"></el-table-column>
				<el-table-column prop="songorder" label="已送出"></el-table-column>
				<el-table-column prop="cost" label="送出/接单金额">
					<template slot-scope="scope" v-if="scope.row">
						<span>{{scope.row.scje?scope.row.scje:0}}/{{scope.row.jdje?scope.row.jdje:0}}</span>
					</template>
				</el-table-column>
				<el-table-column label="操作" fixed="right" width="400px">
					<template slot-scope="scope">
						<div class="dataTable-operator">

							<template v-if="scope.row.neworder!=0">
								<el-button type="primary" @click="NewOrder(scope.$index, scope.row)">接单打印</el-button>
								<el-button type="primary" @click="selectJdPrint(scope.$index, scope.row)">重新补单</el-button>
								<el-button type="primary" @click="selectAllJdPrint(scope.$index, scope.row)">查看</el-button>
								<el-button type="primary" @click="updateps(scope.$index, scope.row)">配送</el-button>
							</template>
							<template v-else-if="scope.row.neworder==0&&scope.row.jieorder==0&&scope.row.songorder!=0">
								<el-button type="info" @click="selectJdPrint(scope.$index, scope.row)">重新打单</el-button>
								<el-button type="info" @click="selectAllJdPrint(scope.$index, scope.row)">查看</el-button>
							</template>
							<template v-else="scope.row.neworder==0&&scope.row.jieorder!=0">
								<el-button type="info" @click="selectJdPrint(scope.$index, scope.row)">重新打单</el-button>
								<el-button type="info" @click="selectAllJdPrint(scope.$index, scope.row)">查看</el-button>
								<el-button type="primary" @click="updateps(scope.$index, scope.row)">配送</el-button>
							</template>
						</div>
					</template>
				</el-table-column>
			</el-table>
			<div class="pageBar">
				<el-pagination @size-change="sizeChange" @current-change="currentChange" :total="listData.total" :page-size="request.page.size"
				 :current-page="request.page.current" :layout="constant.page.layout" :page-sizes="constant.page.pageSizes"></el-pagination>
			</div>
		</div>
		<editDialog :parameter="editParameter" :isDisplay.sync="editDisplay"></editDialog>
		<peisongDialog :parameter="peisongParameter" :isDisplay.sync="peisongDisplay"></peisongDialog>
	</div>
</template>
<script>
	import utils from 'util/utils.js';
	import constant from 'util/constant.js';
	import api from 'api/order/currentorder/currentorder.js';
	import editDialog from './edit.vue';
	import peisongDialog from './peisong.vue';
	export default {
		name: 'orders',
		data() {
			return {
				listLoading: true,
				listData: {},
				state: 1,
				peisongParameter: {},
				editDisplay: false,
				peisongDisplay: false,
				editParameter: {},
				constant: constant,
				request: utils.newRequest(),
				requesttc: utils.newRequest()
			};
		},
		components: {
			editDialog,
			peisongDialog
		},
		methods: {
			//改变选择项
			selectionChange(val) {
				//清空
				this.request.param.ids = [];
				for (let item of val) {
					this.request.param.ids.push(item.id);
				}
			},
			//改变每页显示数量
			sizeChange(val) {
				this.request.page.size = val;
				this.list();
			},
			//改变现在的页码
			currentChange(val) {
				this.request.page.current = val;
				this.list();
			},
			//获取数据
			list() {
				this.listLoading = true;
				let then = this;
				this.request.param.type = then.state; //then.state
				api.orderlist(this.request, response => {
					then.listData = response.data;
					console.log(response.data)
					then.listLoading = false;
				});
			},
			//新订单
			NewOrder(index, row) {
				if (row.type == 1) {
					this.editDisplay = true;
					this.editParameter = {
						eaddrs: row.eaddrs,
						state: 1,
						eid: row.eid,
						type: this.state
					};
				} else {
					this.editDisplay = true;
					this.editParameter = {
						eaddrs: row.eaddrs,
						state: 1,
						eid: row.eid,
						type: this.state,
						etype: row.type
					};
				}

			},
			//已接单
			selectJdPrint(index, row) {

				if (row.type == 1) {
					this.editDisplay = true;
					this.editParameter = {
						eaddrs: row.eaddrs,
						state: 2,
						eid: row.eid,
						type: this.state,
						ispeisong: false
					};
				} else {
					this.editDisplay = true;
					this.editParameter = {
						eaddrs: row.eaddrs,
						state: 2,
						eid: row.eid,
						type: this.state,
						ispeisong: false,
						etype: row.type
					};
				}

			},
			//修改订单状态
			updateps(index, row) {

				if (row.type == 1) {
					this.peisongDisplay = true;
					this.peisongParameter = {
						eaddrs: row.eaddrs,
						state: 2,
						eid: row.eid,
						type: this.state,
						ispeisong: true
					};
				} else {
					this.peisongDisplay = true;
					this.peisongParameter = {
						eaddrs: row.eaddrs,
						state: 2,
						eid: row.eid,
						type: this.state,
						ispeisong: true,
						etype: row.type
					};
				}

			},
			//看全部订单
			selectAllJdPrint(index, row) {
				if (row.type == 1) {
					this.editDisplay = true;
					this.editParameter = {
						eaddrs: row.eaddrs,
						state: 3,
						eid: row.eid,
						type: this.state
					};
				} else {
					this.editDisplay = true;
					this.editParameter = {
						eaddrs: row.eaddrs,
						state: 3,
						eid: row.eid,
						type: this.state,
						etype: row.type
					};
				}
			},
			//删除
			remove(index, row) {
				//单个删除
				if (row) {
					this.request.param.ids = [row.id];
				}
				if (!this.request.param.ids || this.request.param.ids.length == 0) {
					utils.msg.info('请选择至少一行');
					return;
				}
				utils.confirm('确定删除吗？', '提示', () => {
					api.remove(
						this.request,
						response => {
							utils.msg.success(response.msg);
							this.list();
						},
						response => {
							utils.msg.warning(response.msg);
						}
					);
				});
			},
			//搜索
			search() {
				this.list();
			},
			//清空搜索框
			clearSearchVal() {
				this.request.param = {};
			}
		},
		mounted() {
			if (new Date().getHours() >= 0 && new Date().getHours() < 12) {
				this.state = 1;
			} else {
				this.state = 2;
			}


			this.list();
		}
	};
</script>

<style lang="scss">
	@import '~common/custom/css/common.scss';
</style>
